package com.gxa.p2p.controller;

import com.gxa.p2p.common.JsonResult;
import com.gxa.p2p.pojo.Param;
import com.gxa.p2p.service.ParamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author R
 * @data 2021-10-28 16:05
 */
@CrossOrigin
@RestController
@RequestMapping("/param")
@Api("参数配置相关接口")
public class ParamController {

    @Autowired
    ParamService service = null;

    @PostMapping("/findAllParam")
    @ApiOperation("条件或全查询参数配置")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "参数配置名称",required = false,dataType = "String"),
            @ApiImplicitParam(name = "page",value = "页数",required = true,dataType = "int"),
            @ApiImplicitParam(name = "size",value = "记录数",required = true,dataType = "int")
    })
    public Map findAllParam(@RequestParam("name") String name,
                            @RequestParam("page") Integer page,
                            @RequestParam("size") Integer size){
        List<Param> allParam = service.findAllParam(name, page, size);
        Integer allParamCount = service.findAllParamCount(name, page, size);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(allParam);
        jsonResult.setMsg("查询成功");
        jsonResult.put("count",allParamCount);
        return jsonResult.getDataMap();
    }


    @PostMapping("/deleteParam")
    @ApiOperation("删除参数配置")
    @ApiImplicitParam(name = "id",value = "参数配置的id",required = true,dataType = "int")
    public Map deleteParam(@RequestParam("id") Integer id){
        service.deleteParam(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("删除成功");
        jsonResult.setCode("200");
        return jsonResult.getDataMap();
    }

}
